package com.djf.eg.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.djf.eg.entity.Employee;
import com.djf.eg.result.Result;
import com.djf.eg.service.EmployeeService;

@RestController
@RequestMapping("/employees")
public class EmployeeController extends DBaseController {
//	getEmployees: function (page) {
//    return api.get('api/employees')
//  },
//  addEmployee: function (employee) {
//    return api.post('api/employees', employee)
//  },
//  updateEmployee: function (employee) {
//    return api.put('api/employees', employee)
//  },
//  deleteEmployee: function (employeeId) {
//    return api.delete('api/employees/' + employeeId)
//  }
	@Autowired
	private EmployeeService employeeService;
	
	@GetMapping("")
	public Result getEmployees() {
		List<Employee> result = employeeService.getEmployees();
		return Result.success(result);
	}
	
	@PostMapping("")
	public Result addEmployee(@RequestBody Employee employee) {
		employeeService.addEmployee(employee);
		return Result.success();
	}
	
	@PutMapping("")
	public Result updateEmployee(@RequestBody Employee employee) {
		employeeService.updateEmployee(employee);
		return Result.success();
	}
	
	@DeleteMapping("/{id}")
	public Result deleteEmployee(@PathVariable int id) {
		employeeService.deleteEmployee(id);
		return Result.success();
	}
}
